package xnj.lazydog.btcontroller.ControlViews;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;


public class LazyDogView extends View {

    Paint p;
    Resources res;
    float width,height;

    public static final int BMP_MODE_STRICT =0;
    public static final int BMP_MODE_WIDTH_ONLY =1;
    public static final int BMP_MODE_HEIGHT_ONLY =2;
    public static final int BMP_MODE_WRAP =3;


    Bitmap getBitmapScaled(int id,int width,int height,int mode)
    {

        Bitmap b=BitmapFactory.decodeResource(res,id);

        int bw,bh;
        bw = b.getWidth();
        bh = b.getHeight();
        switch (mode)
        {
            case BMP_MODE_STRICT:
                return  Bitmap.createScaledBitmap(b,width,height,true);
            case BMP_MODE_WIDTH_ONLY:
                return Bitmap.createScaledBitmap(b,width,bh*width/bw,true);
            case BMP_MODE_HEIGHT_ONLY:
                return Bitmap.createScaledBitmap(b,bw*height/bh,height,true);
            default:
                if(width*bh<height*bw)
                    return Bitmap.createScaledBitmap(b,width,bh*width/bw,true);
                else
                    return Bitmap.createScaledBitmap(b,bw*height/bh,height,true);
        }
    }
    public LazyDogView(Context context, AttributeSet attrs) {
        super(context, attrs);
        p = new Paint();
        p.setFlags(Paint.FILTER_BITMAP_FLAG);
        p.setAntiAlias(true);
        res = context.getResources();


    }



}
